

#import "FAMHomeGoalsView.h"
@interface FAMHomeGoalsView()
@property (weak, nonatomic) IBOutlet UIView *FAMWeightBackView;
@property (weak, nonatomic) IBOutlet UITextField *FAMWeightTextField;

@end
@implementation FAMHomeGoalsView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"FAMHomeGoalsView" owner:self options:nil];
        self = array.firstObject;
        self.FAMWeightBackView.layer.borderWidth = 1;
        self.FAMWeightBackView.layer.borderColor = kCustom0xColor(0xBABABA, 1.0).CGColor;
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}
- (IBAction)FAM_saveButtonClick:(UIButton *)sender {
    if ([[NSString stringWithFormat:@"%@", self.FAMWeightTextField.text] isEqualToString:@""]) {
        [UIWindow.currentViewController showHint:@"Please enter your weight"];
        return;
    }
    WeakSelf(self)
    [UIWindow.currentViewController showHudInKeyWindowWithHint:nil];
    [FAMHttpTool FAM_PutFoodmateUserdataWithParameters:[NSMutableDictionary dictionaryWithDictionary:@{@"data":@{@"weight":self.FAMWeightTextField.text}}] success:^(FAMFoodmateUserdataModel * _Nonnull model, NSString * _Nonnull msg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIWindow.currentViewController hideHudKeyWindow];
            [FAMUserManger shareInstance].userModel.weight = weakSelf.FAMWeightTextField.text;
            if (weakSelf.block) {
                weakSelf.block(weakSelf.FAMWeightTextField.text);
            }
            [weakSelf removeFromSuperview];
        });
    } failure:^(NSString * _Nonnull errorInfo) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIWindow.currentViewController showHint:errorInfo];
        });
    }];
}
- (IBAction)FAM_closeButtonClick:(UIButton *)sender {
    [self removeFromSuperview];
}

@end
